// 个人中心的菜单组织
window.menus = [
    {
        name: "首页",
        href: "index.html",
    },
    {
        name: "会员专区",
        left: [
            {
                name: "我的账户",
                page: "account"
            },
            {
                name: "密码管理",
                page: "password"
            },
            {
                name: "我的银行卡",
                page: "bank"
            }
        ]
    },
    {
        name: "资金管理",
        left: [
            {
                name: "我要充值",
                page: "charge"
            },
            {
                name: "我要取款",
                page: "take"
            },
            {
                name: "充值记录",
                page: ""
            },
            {
                name: "提款记录",
                page: ""
            }
        ]
    },
    {
        name: "我的投注",
        left: [
            {
                name: "投注记录",
                page: "bet"
            },
            {
                name: "未结明细",
                page: "weijie"
            },
            {
                name: "今日已结",
                page: "today"
            },
            {
                name: "中奖查询",
                page: "bonus"
            }
        ]
    },
    {
        name: "我的报表",
        left: [
            {
                name: "账变记录",
                page: "log"
            },
            {
                name: "日结报表",
                page: "today_win"
            }
        ]
    },
    {
        name: "开奖结果",
        left: [
            {
                name: "北京PK10",
                page: "result_bjpk10"
            },
            {
                name: "中盈PK10",
                page: "result_zypk10"
            },
            {
                name: "重庆时时彩",
                page: "result_cqssc"
            },
            {
                name: "天津时时彩",
                page: "result_tjssc"
            },
            {
                name: "新疆时时彩",
                page: "result_xjssc"
            },
            {
                name: "中盈时时彩",
                page: "result_zyssc"
            },
            {
                name: "广东11选5",
                page: "result_gd115"
            },
            {
                name: "中盈11选5",
                page: "result_zy115"
            },
            {
                name: "北京快乐8",
                page: "result_bjkl8"
            },
            {
                name: "中盈快乐8",
                page: "result_zykl8"
            },
            {
                name: "重庆幸运农场",
                page: "result_cqkl10"
            },
            {
                name: "广东快乐十分",
                page: "result_gdkl10"
            },
            {
                name: "中盈快乐十分",
                page: "result_zykl10"
            },
            {
                name: "江苏骰宝",
                page: "result_jsk3"
            },
            {
                name: "中盈快3",
                page: "result_zyk3"
            },
            {
                name: "香港六合彩",
                page: "result_lhc"
            }
        ]
    },
    {
        name: "代理中心",
        left: [
            {
                name: "会员管理",
                page: ""
            },
            {
                name: "邀请链接",
                page: ""
            },
            {
                name: "团队总览",
                page: ""
            },
            {
                name: "盈亏报表",
                page: ""
            },
            {
                name: "日结报表",
                page: ""
            },
            {
                name: "团队余额",
                page: ""
            }
        ]
    },
    {
        name: "游戏规则",
        left: [
            {
                name: "北京PK10",
                page: "rule_bjpk10"
            },
            {
                name: "中盈PK10",
                page: "rule_zypk10"
            },
            {
                name: "重庆时时彩",
                page: "rule_cqssc"
            },
            {
                name: "新疆时时彩",
                page: "rule_xjssc"
            },
            {
                name: "天津时时彩",
                page: "rule_tjssc"
            },
            {
                name: "中盈时时彩",
                page: "rule_zyssc"
            },
            {
                name: "广东11选5",
                page: "rule_gd115"
            },
            {
                name: "中盈11选5",
                page: "rule_zy115"
            },
            {
                name: "北京快乐8",
                page: "rule_bjkl8"
            },
            {
                name: "中盈快乐8",
                page: "rule_zykl8"
            },
            {
                name: "重庆幸运农场",
                page: "rule_cqkl10"
            },
            {
                name: "广东快乐十分",
                page: "rule_gdkl10"
            },
            {
                name: "中盈快乐十分",
                page: "rule_zykl10"
            },
            {
                name: "江苏骰宝",
                page: "rule_jsk3"
            },
            {
                name: "中盈快3",
                page: "rule_zyk3"
            },
            {
                name: "香港六合彩",
                page: "rule_lhc"
            },
        ]
    }
];

// 填充顶部菜单
var div = $(".top .menu");
div.empty();
for (var i = 0; i < menus.length; i++) {
    if (i < menus.length - 1)
        div.append('<a href="#">' + menus[i].name + '</a><div class="sep"></div>');
    else
        div.append('<a href="#">' + menus[i].name + '</a>');
}
div.append('<div class="clear"></div>');

var arr = $(".top .menu a");
for (var i = 0; i < arr.length; i++) {
    $(arr[i]).click(function(e) {
        var n = $(e.currentTarget).html();
        if (n == '首页') {
            window.location.href = menus[0].href;
            return;
        }

        var n1 = urlInfo.params.n1 || menus[0].name;
        n1 = decodeURI(n1);
        if (n == n1) return;

        refresh_url2(n, '');
        refresh_menu();
        window.location.href = window.location.href;
    });
}

// 更新内容
function refresh_menu() {
    // 取得当前选中的一级、二级菜单名称
    var n1 = urlInfo.params.n1 || menus[1].name, n2 =  urlInfo.params.n2 || '';
    n1 = decodeURI(n1);
    n2 = decodeURI(n2);

    var td = $(".left-menu");
    td.empty();
    for (var i in menus) {
        if (menus[i].name != n1) continue;
        for (var j in menus[i].left) {
            td.append("<a href='#'>" + menus[i].left[j].name + "</a>");
        }
        if (n2 == '' && !menus[i].page) n2 = menus[i].left[0].name;
        break;
    }

    var arr = $(".top .menu a");
    for (var i = 0; i < arr.length; i++) {
        if (n1 == $(arr[i]).html()) {
            $(arr[i]).attr("class", "am-active");
        }
        else {
            $(arr[i]).attr("class", "");
        }
    }

    arr = $(".left-menu a");
    for (var i = 0; i < arr.length; i++) {
        if (n2 == $(arr[i]).html()) {
            $(arr[i]).attr("class", "menu-active");
        }
        else {
            $(arr[i]).attr("class", "");
        }
        $(arr[i]).click(function(e) {
            refresh_url2(n1, $(e.currentTarget).html());
            refresh_menu();
            window.location.href = window.location.href;
        });
    }

    // 载入html文件
    $(".title").html(n2 || n1);
    for (var i in menus) {
        if (menus[i].name != n1) continue;
        for (var j in menus[i].left) {
            if (menus[i].left[j].name == n2) {
                switch_page("center/" + menus[i].left[j].page, $(".operation"));
                return;
            }
        }
        switch_page("center/" + menus[i].page, $(".operation"));
        break;
    }
}
refresh_menu();
